<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增设备')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-device-add">
            <input type="hidden" name="deptId1" id="deptId1"/>
            <input type="hidden" name="deptId2" id="deptId2"/>
            <input type="hidden" name="deptId3" id="deptId3"/>
            <input type="hidden" name="deptName1" id="deptName1"/>
            <input type="hidden" name="deptName2" id="deptName2"/>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">设备名称：</label>
                    <div class="col-sm-8">
                        <input name="name" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">设备类型：</label>
                    <div class="col-sm-8">
                        <select name="type" class="form-control m-b" th:with="type=${@dict.getType('sts_device_type')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">所属组织：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input required id="deptName3" name="deptName3" onclick="selectDeptTree()"  type="text" placeholder="请选择所属组织" class="form-control">
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">设备IP：</label>
                    <div class="col-sm-8">
                        <input name="ipAddress" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">设备识别码：</label>
                    <div class="col-sm-8">
                        <input name="idCode" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">开始时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="activeStartDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">结束时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="activeEndTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">状态：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid">
                            <input type="hidden" id="status" name="status">
                            <input type="checkbox" id="statusCheckbox" checked>
                            <span></span>
                        </label>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="remark" class="form-control"></textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "sts/device"
        $("#form-device-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var status = $("input[id='statusCheckbox']").is(':checked') == true ? 0 : 1;
                $("#status").val(status);
                $.operate.save(prefix + "/add", $('#form-device-add').serialize());
            }
        }

        $("input[name='activeStartDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='activeEndTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        /* 新增-选择部门树 */
        function selectDeptTree() {
            var deptId3 = $("#deptId3").val();
            var deptId = $.common.isEmpty(deptId3) ? "100" : $("#deptId3").val();
            var url = ctx + "sts/device/selectDeptTree/" + deptId;
            var options = {
                title: '选择组织',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            debugger
            console.log(body)
            $("#deptId3").val(body.find('#treeId').val());
            $("#deptName3").val(body.find('#treeName').val());

            $("#deptId1").val(body.find('#treeId1').val());
            $("#deptName1").val(body.find('#treeName1').val());

            $("#deptId2").val(body.find('#treeId2').val());
            $("#deptName2").val(body.find('#treeName2').val());

            $.modal.close(index);
        }
    </script>
</body>
</html>